<template>
	<view class="">
		<view class="Topbg">


		</view>

		<view class="move">
			<view class="mode">
			
					<u-cell-item title="可以兑换数量" :value="moneny" :arrow="false"></u-cell-item>
					<u-cell-item title="当前汇率" :value="withdrawGoldCommission + '金币=1.00元'" :arrow="false"></u-cell-item>
				
			</view>
			
			<view class="mode">
				
					<u-cell-item title="兑换数量" :arrow="false">
						<view slot="right-icon">
							<u-input placeholder="请输入兑换数量" inputAlign="right" v-model="number" @input="change" type="Number"></u-input>
						</view>
					</u-cell-item>
					<u-cell-item title="可兑换金额" :value="transNumber" :arrow="false"></u-cell-item>
				
			</view>
			
			<view style="color:#FF6450;width: 500rpx;margin:40rpx auto 0 auto;text-align: center;" >兑换成功请到钱包中查询</view>
			
		
		</view>
		
		
		<u-button shape="circle"
			:custom-style="{background:'#628DFF',color:'#fff',marginTop:'40rpx',width:'500rpx',marginBottom:'40rpx'}"
			@click="submit">
			立即兑换</u-button>
		
		
			   <u-toast ref="uToast" />
		
		

	</view>
</template>

<script>

	import payway from '../../common/wxpay.js';
	import url from '@/common/baseUrl.js';

	export default {

		data() {
			return {
				imagesurl: url.imageUrl,
				moneny: "",
				withdrawGoldCommission:"",
				number:"",
				transNumber:"",
			
			}
		},
		onLoad() {
			
			this.information()
			
			this.transdetail()
		},
	
		methods: {
			change(e){
				if(Number(this.moneny)<e){
					this.$u.toast("余额不足")
					return
				}
				this.transNumber=(e/this.withdrawGoldCommission).toFixed(2);
			},
			submit(){
				this.$u.post('/api/Financial/goldToCommission', {
					 number:this.number
				}, {}).then(res => {
				
								      this.$refs.uToast.show({
								      		title: '兑换成功',
								      		type: 'success',
											back:true
								      })
				
				}).catch(err => {})
			},
			
			transdetail(){
					this.$u.post('/api/index/getCommission', {
						
					}, {}).then(res => {
						this.withdrawGoldCommission= Number(res.data.withdrawGoldCommission) 
					      
					}).catch(err => {})
				
			},
		
			information(){
				this.$u.post('/api/user/information', {
					
				}, {}).then(res => {
					
					this.moneny=res.data.gold
				}).catch(err => {})
			}
			
		
		}
	}
</script>
<style lang="scss">
	@import 'common.css';
</style>
